<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Choosing a library</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mysqlinfo.api.choosing.html">« Choosing an API</a></li>
      <li style="float: right;"><a href="mysqlinfo.concepts.html">Concepts »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mysql.html">Overview of the MySQL PHP drivers</a></li>
    <li>Choosing a library</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqlinfo.library.choosing" class="chapter">
   <h1>Choosing a library</h1>

   <p class="para">
    The mysqli and PDO_MySQL PHP extensions are lightweight wrappers on
    top of a C client library. The extensions can either use the
    <a href="book.mysqlnd.html" class="link">mysqlnd</a> library or the <code class="literal">libmysqlclient</code>
    library. Choosing a library is a compile time decision.
   </p>
   <p class="para">
    The mysqlnd library is part of the PHP distribution. It offers
    features like lazy connections and query caching, features that are not available
    with libmysqlclient, so using the built-in mysqlnd library is highly recommended.
    See the <a href="book.mysqlnd.html" class="link">mysqlnd documentation</a> for
    additional details, and a listing of features and functionality that it offers.
   </p>
   <p class="para">
    <div class="example" id="example-1405">
     <p><strong>示例 #1 Configure commands for using mysqlnd or libmysqlclient</strong></p>
     <div class="example-contents">
<div class="shellcode"><pre class="shellcode">// Recommended, compiles with mysqlnd
$ ./configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

// Alternatively recommended, compiles with mysqlnd
$ ./configure --with-mysqli --with-pdo-mysql

// Not recommended, compiles with libmysqlclient
$ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysql_config</pre>
</div>
     </div>

    </div>
   </p>
   <p class="para">
    <em class="emphasis">Library feature comparison</em>
   </p>
   <p class="para">
    It is recommended to use the <a href="book.mysqlnd.html" class="link">mysqlnd</a>
    library instead of the MySQL Client Server library (libmysqlclient). Both
    libraries are supported and constantly being improved.
   </p>
   <table id="mysqlinfo.library.choosing.changelog" class="doctable informaltable">
    
     <thead>
      <tr>
       <th class="empty">&nbsp;</th>
       <th>MySQL native driver (<a href="book.mysqlnd.html" class="link">mysqlnd</a>)</th>
       <th>MySQL client server library (<code class="literal">libmysqlclient</code>)</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>Part of the PHP distribution</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>PHP version introduced</td>
       <td>5.3.0</td>
       <td>N/A</td>
      </tr>

      <tr>
       <td>License</td>
       <td>PHP License 3.01</td>
       <td>Dual-License</td>
      </tr>

      <tr>
       <td>Development status</td>
       <td>Active</td>
       <td>Active</td>
      </tr>

      <tr>
       <td>Lifecycle</td>
       <td>No end announced</td>
       <td>No end announced</td>
      </tr>

      <tr>
       <td>Compile default (for all MySQL extensions)</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>Compression protocol support</td>
       <td>Yes</td>
       <td>Yes</td>
      </tr>

      <tr>
       <td>SSL support</td>
       <td>Yes</td>
       <td>Yes</td>
      </tr>

      <tr>
       <td>Named pipe support</td>
       <td>Yes</td>
       <td>Yes</td>
      </tr>

      <tr>
       <td>Non-blocking, asynchronous queries</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>Performance statistics</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>LOAD LOCAL INFILE respects the <a href="ini.core.html#ini.open-basedir" class="link">open_basedir directive</a></td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>Uses PHP&#039;s native memory management system (e.g., follows PHP memory limits)</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>Return numeric column as double (COM_QUERY)</td>
       <td>Yes</td>
       <td>No</td>
      </tr>

      <tr>
       <td>Return numeric column as string (COM_QUERY)</td>
       <td>Yes</td>
       <td>Yes</td>
      </tr>

      <tr>
       <td>Plugin API</td>
       <td>Yes</td>
       <td>Limited</td>
      </tr>

      <tr>
       <td>Automatic reconnect</td>
       <td>No</td>
       <td>Optional</td>
      </tr>

     </tbody>
    
   </table>

  </div>
</div></div></body></html>